package com.aldobucchi.ds.container.zet.impl
{
	
	import com.aldobucchi.ds.container.IRContainer;
	import com.aldobucchi.ds.container.impl.AbstractRWDictionaryContainer;
	import com.aldobucchi.ds.container.zet.IRWSet;

	public class RWDictionarySet extends AbstractRWDictionaryContainer implements IRWSet
	{
		
		
		/**
		 * 
		 * 
		 * 
		 * @param source
		 * 
		 */
		public function RWDictionarySet( source:* = null )
		{
		
			if ( source is Array )
			{
				var arr:Array = source as Array;
				for each ( var e:* in arr )
				{
					add( e );				
				}
			}
			else if ( source is IRContainer )
			{
				var c:IRContainer = source as IRContainer;
				c.walk( function( e:*, m:int ):void{
						add( e );
					} );			
			}
		
		}
		
		
		
		

		public function add( e:* ):void
		{
			if ( m( e ) === 0 )
			{
				m( e, 1 );								
			}
		}
		
		
		
		// we know that our multiplicity is always equal to one
		// so we can just use a for... loop and treat each key as an element
		// this is much faster than calling walk( )
		override public function get asArray( ):Array
		{
			var arr:Array = new Array( );
		
			for ( var e:* in dict )
			{
				arr.push( e );
			}
		
			return arr;
		}
		
		
		

		
	}
	
	
}
